package com.cmcc.xdr.message;

import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.cmcc.xdr.entity.SipSrvccEntity;
import com.cmcc.xdr.util.TBCDUtil;

public class SingleSigSipSrvccMsg extends SingleSigMsg {


	public SipSrvccEntity sipSrvcc = new SipSrvccEntity();
	private static SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

	public SingleSigSipSrvccMsg(ByteBuffer buffer,SingleSigGlobalMsg globalMsg) {
		this.setBuffer(buffer);
		this.setSSGMsg(globalMsg);

		sipSrvcc.setLength(globalMsg.getTotalLength());
		sipSrvcc.setLocalProvince(globalMsg.getLocalProvince());
		sipSrvcc.setLocalCity(globalMsg.getLocalCity());
		sipSrvcc.setOwnerProvince(globalMsg.getOwnerProvince());
		sipSrvcc.setOwnerCity(globalMsg.getOwnerCity());
		sipSrvcc.setRoamingType(globalMsg.getRoamingType());
		sipSrvcc.setInterFace(globalMsg.getInterfaceType());
		sipSrvcc.setXdrId(globalMsg.getXdrID());
		sipSrvcc.setRat(globalMsg.getRat());
		sipSrvcc.setImsi(globalMsg.getImsi());
		sipSrvcc.setImei(globalMsg.getImei());
		sipSrvcc.setMsisdn(globalMsg.getMsisdn());
		
		sipSrvcc.setProcedureType(loadInt(1));
		sipSrvcc.setProcedureStartTime(new Date(loadLong(8)));
		sipSrvcc.setProcedureEndTime(new Date(loadLong(8)));
		sipSrvcc.setProcedureStatus(loadInt(1));
		sipSrvcc.setCallingNumber(loadStr(16)); 
		sipSrvcc.setCallingPartyUri(loadStr(32)); 
		sipSrvcc.setRequestUri(loadStr(32));
		sipSrvcc.setUserIp(loadIp(16)); 
		sipSrvcc.setCallId(loadStr(128)); 
		sipSrvcc.setIcId(loadStr(64));
		sipSrvcc.setSourceNeIp(loadIp(16)); 
		sipSrvcc.setSourceNePort(loadInt(2)); 
		sipSrvcc.setDestNeIp(loadIp(16)); 
		sipSrvcc.setDestNePort(loadInt(2)); 
		sipSrvcc.setSourceAccessType(loadInt(1)); 
		sipSrvcc.setSourceEci(loadStr(4));
		sipSrvcc.setSourceTac(loadStr(2));
		sipSrvcc.setSourceImsi(loadStr(8)); 
		sipSrvcc.setSourceImei(loadStr(8)); 
		sipSrvcc.setDestAccessType(loadInt(1)); 
		sipSrvcc.setDestEci(loadStr(4));
		sipSrvcc.setDestTac(loadStr(2));
		sipSrvcc.setDestImsi(loadStr(8)); 
		sipSrvcc.setDestImei(loadStr(8)); 
		sipSrvcc.setCallingSdpIpAddr(loadIp(16)); 
		sipSrvcc.setCallingAudioSdpPort(loadInt(2));
		sipSrvcc.setCallingVideoSdpPort(loadInt(2));
		sipSrvcc.setCalledSdpIpAddr(loadIp(16));
		sipSrvcc.setCalledAudioSdpPort(loadInt(2)); 
		sipSrvcc.setCalledVideoPort(loadInt(2));
		sipSrvcc.setAudioCodec(loadInt(1)); 
		sipSrvcc.setVideoCodec(loadInt(1));		
		sipSrvcc.setResponseCode(loadInt(2)); 
		sipSrvcc.setFinishWarningCode(loadInt(2));
		sipSrvcc.setFinishReasonProtocol(loadInt(1)); 
		sipSrvcc.setFinishReasonCause(loadInt(2));
		sipSrvcc.setFirfailtime(loadInt(4));
		sipSrvcc.setFirstFailNeIp(loadIp(16));
		sipSrvcc.setFirstFailTransaction(loadInt(1)); 
		sipSrvcc.setAlertingTime(loadInt(4)); 
		sipSrvcc.setAnswerTime(loadInt(4)); 
		sipSrvcc.setReleaseTime(loadInt(4));
		sipSrvcc.setCallDuration(loadInt(4)); 
		sipSrvcc.setAtuSti(loadStr(64));
		sipSrvcc.setCMsisdn(TBCDUtil.toTBCD(loadByte(16)));
		sipSrvcc.setSsi(loadHexStr(16));


		sipSrvcc.setInsertDate(format.format(new Date()));
	}

	public SipSrvccEntity getSipSrvcc() {
		return sipSrvcc;
	}

	public void setSipSrvcc(SipSrvccEntity sipSrvcc) {
		this.sipSrvcc = sipSrvcc;
	}

}